package cn.tedu.course.carousel.service.impl;

import cn.tedu.course.carousel.mapper.CarouselMapper;
import cn.tedu.course.carousel.pojo.dto.CarouselQuery;
import cn.tedu.course.carousel.pojo.dto.CarouselSaveParam;
import cn.tedu.course.carousel.pojo.entity.Carousel;
import cn.tedu.course.carousel.pojo.vo.CarouselVO;
import cn.tedu.course.carousel.service.CarouselService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class CarouselServiceImpl implements CarouselService {
    @Autowired
    CarouselMapper carouselMapper;
    @Override
    public List<CarouselVO> selectCarousel(CarouselQuery carouselQuery) {
        log.debug("查询轮播图业务:carousel={}",carouselQuery);
        List<CarouselVO> list = carouselMapper.selectCarousel(carouselQuery);
        return list;
    }

    @Override
    public void saveCarousel(CarouselSaveParam carouselSaveParam) {
        log.debug("保存轮播图业务:carouselsaveparam={}",carouselSaveParam);
        Carousel carousel = new Carousel();
        BeanUtils.copyProperties(carouselSaveParam, carousel);
        System.out.println("获取id...."+carousel.getId());
        if (carousel.getId()==null) {

            carouselMapper.insert(carousel);
        } else {
            carouselMapper.update(carousel);

        }

    }

    @Override
    public void deleteCarousel(Long carouselId) {
        log.debug("删除轮播图业务:carouselId={}",carouselId);
        carouselMapper.deleteById(carouselId);
    }
}
